$(function(){
   var baseurl = $('#baseurl').val();
   $('#search_chuyenbay').submit(function (){ 
        $.ajax({
            url: baseurl + '/index.php/nhanvien/chuyenbay/search',
            data: $('#search_chuyenbay').serialize(),
            type: 'POST',
            success: function (result){
                    $('#InsertIntoMe').hide();
                    document.getElementById('InsertIntoMe').innerHTML=result;
                    $('#InsertIntoMe').slideDown('slow');    
            }
        });
        return false;
    }); 
    $('#search_ghetrong').submit(function (){ 
        $.ajax({
            url: baseurl + '/index.php/nhanvien/chuyenbay/load_ghe_trong',
            data: $('#search_ghetrong').serialize(),
            type: 'POST',
            success: function (result){
                    $('#InsertIntoMe').hide();
                    document.getElementById('InsertIntoMe').innerHTML=result;
                    $('#InsertIntoMe').slideDown('slow');    
            }
        });
        return false;
    });
    $('#search_list_khachhang').submit(function (){ 
        $.ajax({
            url: baseurl + '/index.php/nhanvien/chuyenbay/load_list_khachhang',
            data: $('#search_list_khachhang').serialize(),
            type: 'POST',
            success: function (result){
                    $('#InsertIntoMe').hide();
                    document.getElementById('InsertIntoMe').innerHTML=result;
                    $('#InsertIntoMe').slideDown('slow');    
            }
        });
        return false;
    });
    
    $('body').on('click','#KHNL tbody tr', function(e){
      var data= 'MSKH='+$(this).children('td:first').text();
      $.ajax({
            url: baseurl + '/index.php/nhanvien/khachhang/load_khachhang',
            data: data, 
            type: 'POST',
            success: function (result){
                    document.getElementById('modal_content').innerHTML=result;
                    //alert(result);
                    $('#popup_khachhang').modal('show');
            }
        });
    });
    $('body').on('click','#KHTE tbody tr', function(e){
      var data= 'MSKH='+$(this).children('td:first').text();
      $.ajax({
            url: baseurl + '/index.php/nhanvien/khachhang/load_khachhang',
            data: data, 
            type: 'POST',
            success: function (result){
                    document.getElementById('modal_content').innerHTML=result;
                    //alert(result);
                    $('#popup_khachhang').modal('show');
            }
        });
    });
    $('#search_khachhang').submit(function (){ 
        $.ajax({
            url: baseurl + '/index.php/nhanvien/khachhang/load_khachhang',
            data: $('#search_khachhang').serialize(),
            type: 'POST',
            success: function (result){
                if (result=='')
                {
                    $('#result_panel').hide();
                    $('#attention').hide();
                    $('#attention').slideDown('slow');
                }else{
                    $('#result_panel').hide();
                    $('#attention').hide();
                    document.getElementById('InsertIntoMe').innerHTML=result;
                    $('#result_panel').slideDown('slow');  
                }    
            }
        });
        return false;
    });
    $('#update_KLHH').submit(function (){ 
        $.ajax({
            url: baseurl + '/index.php/nhanvien/khachhang/update_KLHH',
            data: $('#update_KLHH').serialize(),
            type: 'POST',
            success: function (result){
                    $('#InsertIntoMe').hide();
                    document.getElementById('InsertIntoMe').innerHTML=result;
                    $('#InsertIntoMe').slideDown('slow');  
                }    
            });
        return false;
    });
    $('#insert_chuyenbay').submit(function (){ 
        $.ajax({
            url: baseurl + '/index.php/nhanvien/chuyenbay/taolich',
            data: $('#insert_chuyenbay').serialize(),
            type: 'POST',
            success: function (result){
                    $('#InsertIntoMe').hide();
                    document.getElementById('InsertIntoMe').innerHTML=result;
                    $('#InsertIntoMe').slideDown('slow');  
                }    
            });
        return false;
    });
    $('#find-khachhang').submit(function (){ 
        $.ajax({
            url: baseurl + '/index.php/nhanvien/khachhang/search_KH',
            data: $('#find-khachhang').serialize(),
            type: 'POST',
            success: function (result){
                    $('#InsertIntoMe').hide();
                    $('#InsertIntoMe').hide();
                    document.getElementById('InsertIntoMe').innerHTML=result;
                    $('#InsertIntoMe').slideDown('slow');  
                }    
            });
        return false;
    });
    $('body').on('submit','#update-ghe',function (){ 
        document.getElementById('status').innerHTML='<img src="'+baseurl+'img_home/loading.gif">';
        $.ajax({
            url: baseurl + '/index.php/nhanvien/khachhang/update_ghe',
            data: $('#update-ghe').serialize(),
            type: 'POST',
            success: function (result){
                    document.getElementById('gheso').innerHTML=result;
                    document.getElementById('status').innerHTML='<img src="'+baseurl+'img_home/success1.png">'; 
                }    
            });
        return false;
    });
});


